<?include_once('conn.php');?>
<?include_once('inc_head.php');?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$act=$_GET['act'];
$series=isset($series)?$series:0;
$listTable = TABLE_C."user";

#/////////////////////////删除/////////////////////
if($act=='del') {	
	$id=addslashes($_GET['id']); 
	//从数据数据库
	$cmd="delete from $listTable where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
	gourl('删除成功！',$cururl);	
	}
	exit;
}

////////////////////////////////////  复选框批量操作   ///////////////////////////////////////////////
if($act=="doall"){
	 $doact=$_POST['doact'];#子动作
	 $idarr=$_POST['checkbox'];
	  if($_POST['checkbox']==""){gourl("没有选择序列！",$cururl);exit;}#是否有选择
	 $allID=implode(",",$_POST['checkbox']);#处理ID
	 $orderVal=intval($_POST['orderVal']);#排序的值 
	 switch($doact){
		 #更改排序
		 case "orderby":
		 if($orderVal==0){gourl("排序数字无效",$cururl);}
		 $cmd="update $listTable set orderby=$orderVal where id in($allID)";
		 if(mysql_query($cmd) or die(mysql_error())){
			gourl("已经将ID为".$allID."的记录批量排序。",$cururl);
		 }
		 
		 break;
		 
		 #移动
		 case "moveto":
		 $tosid=intval($_POST['moveseries']);
		 $cmd="update $listTable set series=$tosid where id in($allID)";
		 if(mysql_query($cmd) or die(mysql_error())){
			gourl("已经将ID为".$allID."的记录批量移动",$cururl);
		 }
		 break;
		 
		 #批量删除
		 case "del":
			 for($i=0;$i<count($idarr);$i++){
				$id=$idarr[$i];
				echo "<br>处理ID为 $id 的记录:";
				//从数据数据库
				$cmd="delete from $listTable where id=".$id;
				if(mysql_query($cmd) or die(mysql_error())){
					echo "<div class=tipsok>成功从数据库删除</div>";
				}
				#删除结束
			 }
			 echo " 点击 <a href=".$_SESSION['lastUrl'].">这里</a> 返回";
		 break;
	 }
	 exit;
}
?>



<body>
<?local("用户列表");?>
<div id="intro">
<!-------------------------------------默认状态------------------------------------->
<table width="100%" border="0"  cellpadding="2" cellspacing="0">
  <tr> 
      <td width="50%"> 
			<select name="smallname" id="smallname"  onchange="selectSeries(this.value)">
			<option  value="0" style="background:yellow;">全部</option>
			 <?
				// $cmd1="select * from $listTable order by id";
				// $rs1=mysql_query($cmd1) or die(mysql_error());
				// while($row1=mysql_fetch_assoc($rs1)){
				// 	if($row1['id']==$_GET['sid']){
				// 		echo '<option selected value='.$row1[id].'>'.$row1[name].'</option>';
				// 	}else{
				// 		echo '<option value='.$row1[id].'>'.$row1[name].'</option>';
				// 	}
				// }
				// mysql_free_result($rs1);
			?>
			</select>
		    <?
			#显示排序
			echo " <a href='?sid=$series&okey=id asc' class='btn btn-md btn-default'>ID▲</a> ";
			echo " <a href='?sid=$series&okey=id desc' class='btn btn-md btn-default'>ID▼</a>";
		    ?>
       </td>
			
      <td width="50%" align=right> 
        <?	
        $okey=get2('okey');
		$page=intval($_GET['page']);
		if($page==0){$page=1;}
		$pagesize=$news_pagesize;
		$rsStar=$page*$pagesize-$pagesize;

		// 判断条件
		if($_GET['company']){
			$condition=" where u.company = {$_GET['company']}";
		}elseif($_GET['area']){
			// $condition=" where u.service_area = {$_GET['area']}";
		}else{
			$condition=" ";
		}

		//总数
		$cmd="select  id from $listTable u  $condition";
		
		$rs=mysql_query($cmd) or die(mysql_error());
		$rstotal=mysql_num_rows($rs);
		
		//排序整理
		$orderTxt=" order by  u.$okey ";
		if($okey==''){
			$orderTxt=' order by u.id desc';
		}
		
		$cmd="select u.*,c.title company_cn,qn.count qn_count from $listTable u
		left join(select id,title from ".TABLE_C."company) c on c.id=u.company 
		left join(select count(id) count,id,unionid from {$TABLE}vote_qn group by unionid) qn on qn.unionid=u.unionid 
		$condition $orderTxt LIMIT $rsStar,$pagesize
		";
		$rs=mysql_query($cmd) or die(mysql_error());	
		$pagetotal=ceil($rstotal/$pagesize);
		echo "<div>当前分类记录数共【".$rstotau."】条,每页显示【".$pagesize."】条 ,页码：$page/$pagetotal</div>";
		 ?>
	  </td>
          </tr>
        </table>
	<!--主内容表格-->
<form name="form_all" method=post action="?act=doall" style="margin:0px">
  <table class="table table-hover table-bordered table-striped" width="100%" border="0"  cellpadding="0" cellspacing="0" >
    <tr> 
      <th width="30"  >&nbsp;</th>
      <th width="70"  >ID</th>
      <th width="" >头像</th>
      <th width="" >unionid </th>
      <th width="" >openid </th>
      <th width="" >呢称 </th>
      <th width="" >国家 </th>
      <th width="" >省份 </th>
      <th width="" >城市 </th>
      <th width="" >性别</th>
      <th width="" >联系人</th>
      <th width="" >联系电话</th>
      <th width="" >公司名称</th>
      <th width="" >问卷数</th>
      <th width="150"  >操作</th>
    </tr>
    <?
	// 性别映射
	$gender_cn = Array( "1"=>"男", "2"=>"女" );
	// 公司映射？？

	// 循环开始
	while($row=mysql_fetch_assoc($rs)){
	  $id=$row['id'];
  	?>
    <tr  class="mytr" > 
      <td align="center"  > <input type=checkbox value="<? echo $id ?>" name="checkbox[]"></td>
      <td align="center" ><? echo $id ?></td>
      <td align=""><img src="<? echo $row['avatarUrl'];?>" height=40></td>
      <td align=""><? echo $row['unionid'];?></td>
      <td align=""><? echo $row['openid'];?></td>
      <td align=""><? echo $row['nickName'];?></td>
      <td align=""><? echo $row['country'];?></td>
      <td align=""><? echo $row['province'];?></td>
      <td align=""><? echo $row['city'];?></td>
	  <td align=""><? echo $gender_cn[$row['gender']];?></td>
	  <td align=""><? echo $row['contact_name'];?></td>
	  <td align=""><? echo $row['contact_tel'];?></td>
	  <td align=""><? echo $row['company_cn'];?></td>
	  <td align="center"><? echo $row['qn_count'];?></td>
      <td align="center" > 
		<!-- <a href="admin_vote_edit.php?id=<?echo $id?>" class="btn btn-xs btn-info" rel="floatEdit" target="_blank">编辑</a>  -->
		<a href="admin_questionneair.php?unionid=<?echo $row['unionid']?>" class="btn btn-xs btn-info" rel="floatEdit__" target="_blank">问卷</a>
 		<a  href="javascript:if(confirm('确定吗')){window.location='?act=del&id=<?echo $id?>&vfile=<? echo $rowL['videofile'];?>&imgf=<?echo $rowL['imagefile'];?>'}" class="btn btn-xs btn-danger">删除</a> 
       </td>
    </tr>
    <?}?>
  </table>

  <!--下面的控制表格-->

	<div class="p5"><? echo turnpage2($pagesize,$rstotal);?></div>

  </form>
  
</div>
<?include('inc_foot.php');?>
</body>
</html>